<?php
/**
 * @author GhostWei
 * @date Oct 7, 2012
 */
class system_user_permission_concept extends system_concept_abstract {
	
	public function init() {
		$this->setModel('system_user_permission_model', 'permission');
		$this->setModelCols('permission', array('user_id', 'group_id'));
	}

	public function save($row) {
		$row->set('user_id', intval($row->get('user_id')));
		$row->set('group_id', intval($row->get('group_id')));
		
		if($row->getUserId() && $row->getGroupId() && 
				!$this->fetch(array('user_id = ?' => $row->getUserId(), 'group_id = ?' => $row->getGroupId()))
			) {
			$this->getModel('permission')->insert($row->getModelData('permission'));
		}
		return $row;
	}

}
